package aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class PerformanceAspect {

    @Around("Pointcuts.allServices()")
    public Object performance(ProceedingJoinPoint joinPoint) {

        Object result = null;
        try {
            Long start = System.currentTimeMillis();

            result = joinPoint.proceed();

            Long end = System.currentTimeMillis();
            long elapsed = end - start;
            System.out.println("业务方法执行消耗时长：" + elapsed);
        } catch (Throwable e) {
            e.printStackTrace();
        }

        return result;

    }

}
